<template>
  <div class="farmland-edit f-c">
    <div v-show="showAdd" class="top">
      <div class="top-back" @click="back">
        <i class="el-icon-arrow-left" />
        返回
      </div>
      新增田块
    </div>
    <div class="f-g map-container">
      <div v-show="!showAdd" class="search-box">
        <el-input v-model="searchInput" clearable class="search-input" prefix-icon="el-icon-search" placeholder="搜索田块所在的区域" />
        <el-button v-show="!showTips" type="primary" @click="onSearch">圈田</el-button>
        <el-button v-show="showTips" type="danger" @click="onDelete">删除</el-button>
      </div>
      <Map ref="map" @set-area="onSetArea" />
      <div class="farmland-edit-drawer" :style="{ right: right }">
        <i class="el-icon-close" @click="closeAdd" />
        <div class="drawer-content">
          <el-form :model="ruleForm">
            <el-form-item required prop="name" label="田的名称">
              <el-input v-model="ruleForm.name" clearable placeholder="请输入田地名称" />
            </el-form-item>
            <el-form-item required prop="area" label="田的面积">
              <span class="form-value">{{ ruleForm.area }}</span>
              亩
              <span class="form-value">2</span>
              分
            </el-form-item>
            <el-form-item required prop="name" label="田的周长">
              <span class="form-value">{{ 1000 }}</span>
              米
            </el-form-item>
            <el-form-item required label="种植作物">
              <el-select v-model="ruleForm.name" clearable placeholder="请选择种植作物">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item required prop="name" label="品种">
              <el-input v-model="ruleForm.name" clearable placeholder="请输入品种" />
            </el-form-item>
            <el-form-item required prop="name" label="播种时间">
              <el-date-picker
                v-model="ruleForm.name"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="请选择播种时间"
              />
            </el-form-item>
            <el-form-item required label="土地类型">
              <el-select v-model="ruleForm.name" clearable placeholder="请选择土地类型">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item required prop="name" label="种植密度">
              <el-input v-model="ruleForm.name" clearable placeholder="请输入种植密度" />
              <span class="form-value">粒(斤/颗)/亩</span>
            </el-form-item>
            <el-form-item required prop="name" label="灌溉方式">
              <el-input v-model="ruleForm.name" clearable placeholder="请输入灌溉方式" />
            </el-form-item>
            <el-form-item required prop="name" label="种植农户">
              <el-input v-model="ruleForm.name" clearable placeholder="请输入农户姓名" />
            </el-form-item>
            <el-form-item required prop="name" label="联系方式">
              <el-input v-model="ruleForm.name" clearable placeholder="请输入农户电话" />
            </el-form-item>
            <el-form-item required prop="name" label="负责人">
              <el-input v-model="ruleForm.name" clearable placeholder="请输入负责人" />
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer" style="text-align: right">
            <el-button type="primary" @click="drawer = false">保存</el-button>
          </div>
        </div>
      </div>
    </div>
    <MapTool />
    <div v-if="showTips && !showAdd" class="showTips f-r j-b a-c">
      <div class="item-list f-r a-c">
        <div class="item">
          <div class="name">面积</div>
          <div class="value">{{ detail.area }}平方米</div>
        </div>
        <div class="item">
          <div class="name">海拔</div>
          <div class="value" />
        </div>
        <div class="item">
          <div class="name">坡度</div>
          <div class="value" />
        </div>
        <div class="item">
          <div class="name">周长</div>
          <div class="value" />
        </div>
      </div>
      <el-button type="primary" @click="openAdd">下一步</el-button>
    </div>
  </div>
</template>

<script>
import Map from '@/views/farmland/map';
export default {
  name: 'FarmalndAdd',
  components: {
    Map
  },
  data() {
    return {
      drawer: false,
      searchInput: '',
      ruleForm: {

      },
      options: [],
      buttonRight: '30px',
      right: '-500px',
      // 绘制提示
      showTips: false,
      // 去新增
      showAdd: false,
      detail: {
        area: ''
      }
    }
  },
  methods: {
    onSearch() {},
    onSetArea(area) {
      this.showTips = true
      this.detail.area = area
    },
    onDelete() {
      this.$refs.map.map.clearMap()
      this.showTips = false
      this.detail = {
        area: ''
      }
    },
    openAdd() {
      this.showAdd = true
      this.right = '0px'
      this.buttonRight = '530px'
      // 设置添加表单
      this.ruleForm = {
        area: this.detail.area
      }
    },
    closeAdd() {
      this.showAdd = false
      this.right = '-500px'
      this.buttonRight = '30px'
    },
    back() {
      this.$router.back()
    }
  }
}
</script>

<style scoped lang="scss">
.farmland-edit {
  height: 100%;
  .top {
    margin-top: -10px;
    margin-bottom: 10px;
    width: 100%;
    height: 63px;
    background: #ffffff;
    border-radius: 2px;
    position: relative;
    text-align: center;
    font-size: 18px;

    font-weight: 600;
    line-height: 63px;
    color: #333333;
    .top-back {
      cursor: pointer;
      position: absolute;
      left: 18px;
      top: 50%;
      transform: translateY(-50%);
      i {
        font-size: 15px;
        color: #333333;
      }
      font-size: 16px;

      font-weight: 400;
      line-height: 22px;
      color: #333333;
      opacity: 1;
    }
  }
  .map-container {
    overflow: hidden;
    position: relative;
    .edit-btn {
      position: absolute;
      right: 36px;
      top: 20px;
      z-index: 99;
    }
  }
  .farmland-edit-drawer {
    position: absolute;
    height: 100%;
    top: 0;
    z-index: 100;
    transition: all 0.3s;
    .drawer-content {
      overflow: auto;
      height: 100%;
      background-color: #ffffff;
      width: 500px;
      padding: 20px;
      ::v-deep .el-form {
        .el-form-item {
          .el-input,
          .el-select {
            width: 100% !important;
          }
        }
      }
    }
    .form-value {
      font-size: 14px;

      font-weight: 400;
      line-height: 20px;
      color: #333333;
      padding: 0 20px;
    }
    i {
      position: absolute;
      right: 20px;
      top: 12px;
      color: #2b2f3a;
      font-size: 24px;
    }
  }
  .search-box {
    position: absolute;
    left: 64px;
    top: 28px;
    z-index: 20;
    ::v-deep .el-input {
      width: 722px !important;
      background: rgba(255,255,255,0.39);
      opacity: 0.74;
      margin-right: 15px;
    }
  }
  .showTips {
    width: 100%;
    height:60px;
    position: absolute;
    left: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    padding: 0 67px 0 97px;
    z-index: 99;
    .item-list {
      .item {
        margin-right: 100px;
        font-size: 14px;

        font-weight: bold;
        line-height: 24px;
        color: #FFFFFF;
      }
    }
  }
}
</style>
